package org.blackcat.web;

import org.blackcat.core.annotation.Login;
import org.blackcat.domain.Temperature;
import org.blackcat.domain.common.MsgResponse;
import org.blackcat.domain.enums.UserEnum;
import org.blackcat.service.TemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 詹泽
 * @date 2017/2/22
 */
@RestController
@RequestMapping("/temperature")
public class TemperatureController {

    @Autowired
    private TemperatureService temperatureService;

    @RequestMapping(method = RequestMethod.PUT)
    @Login
    public MsgResponse<Object> addTemperature(Temperature temperature, HttpServletRequest request) throws Exception {
        String token = (String) request.getAttribute(UserEnum.USER_REQUEST_TOKEN.getValue());
        return temperatureService.addTemerature(temperature,token);
    }

    @RequestMapping(value = "/{date}/{status}",method = RequestMethod.GET)
    @Login
    public MsgResponse<List<Temperature>> listTemperature(@PathVariable String date,@PathVariable int status, HttpServletRequest request) throws Exception {
        String token = (String) request.getAttribute(UserEnum.USER_REQUEST_TOKEN.getValue());
        return temperatureService.listTemerature(date,status,token);
    }
}
